using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;

using FarseerPhysics.Dynamics.Contacts;

namespace Spacer {
	public class Pickup : Entity {
		public Pickup() {}

		public Pickup( SolarSys world ) : base(world) {
			if( this.GetType() == typeof(Pickup) ) Initialize();
		}

		public override void Initialize() {
			base.Initialize();

			Texture = Main.Textures["Item"];
			DrawColor = new Color( 1f, 1f, 1f, 1f );

			PhysicsInitCircle( 0.25f, MovementMode.Normal );

			Invulnerable = true;
			ItemType = typeof( Item );
		}

		// ----------

		public override bool OnCollision( Entity other, Contact contact ) {
			if( IsMarkedForRemoval || !(other is Pawn) )
				return false;

			if( ItemType != typeof(Item) && !ItemType.IsSubclassOf(typeof(Item)) )
				return false;

			Item item = (Item)Activator.CreateInstance( ItemType, World );
			if( item == null )
				return false;

			item.GiveTo( (Pawn)other );
			Remove();

			return false;
		}

		// ----------

		public Type ItemType { get; set; }
	}
}